/**
 *  app share
 */
$(function () {

    layui.use(['form', 'tableSelect'], function () {
        let form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            $ = layui.$;
    });
});

var _this;
let loginU;
var clipboard;
let courseData;
new Vue({
    el: '#appContainVue',
    data:{
        courseId:0,
        padCount:0,
        shareCode: '',
        qrcodeUrl:'',
        validDay:'0',
        createFlag:false,
    },
    mounted(){
        _this=this;
        let u=localStorage.getItem("a@m");
        loginU=decryptLocalStorage(u);
        let _data=localStorage.getItem("appData");
        let appData=decryptLocalStorage(_data,loginU.token);
        let qrcodeUrl=appData.basePath+"/admin/v1/common/downloadApk?filePath="+appData.newAppUrl;
        _this.qrcodeUrl=qrcodeUrl;
        $("#qrcodeCanvas").qrcode({text: _this.qrcodeUrl});
    },
    methods:
        {
            handleChange(value) {
                // console.log(value);
            },
            downloadShareCode()
            {
                var canvas = $('#qrcodeCanvas').find("canvas").get(0);
                try {//解决IE转base64时缓存不足，canvas转blob下载
                    var blob = canvas.msToBlob();
                    navigator.msSaveBlob(blob, 'qrcode.jpg');
                } catch (e) {//如果为其他浏览器，使用base64转码下载
                    var url = canvas.toDataURL('image/jpeg');
                    $("#download").attr('href', url).get(0).click();
                }
                return false;
            }

        }
});